home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / guile-ii.src / guile-ii / guile-src / libguile / eq.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-16  |  4.2 KB  |  161 lines

  1. /*    Copyright (C) 1995 Free Software Foundation, Inc.
  2.  * 
  3.  * This program is free software; you can redistribute it and/or modify
  4.  * it under the terms of the GNU General Public License as published by
  5.  * the Free Software Foundation; either version 2, or (at your option)
  6.  * any later version.
  7.  * 
  8.  * This program is distributed in the hope that it will be useful,
  9.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.  * GNU General Public License for more details.
  12.  * 
  13.  * You should have received a copy of the GNU General Public License
  14.  * along with this software; see the file COPYING.  If not, write to
  15.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  16.  *
  17.  * As a special exception, the Free Software Foundation gives permission
  18.  * for additional uses of the text contained in its release of GUILE.
  19.  *
  20.  * The exception is that, if you link the GUILE library with other files
  21.  * to produce an executable, this does not by itself cause the
  22.  * resulting executable to be covered by the GNU General Public License.
  23.  * Your use of that executable is in no way restricted on account of
  24.  * linking the GUILE library code into it.
  25.  *
  26.  * This exception does not however invalidate any other reasons why
  27.  * the executable file might be covered by the GNU General Public License.
  28.  *
  29.  * This exception applies only to the code released by the
  30.  * Free Software Foundation under the name GUILE.  If you copy
  31.  * code from other Free Software Foundation releases into a copy of
  32.  * GUILE, as the General Public License permits, the exception does
  33.  * not apply to the code that you add in this way.  To avoid misleading
  34.  * anyone as to the status of such modified files, you must delete
  35.  * this exception notice from them.
  36.  *
  37.  * If you write modifications of your own for GUILE, it is your choice
  38.  * whether to permit this exception to apply to your modifications.
  39.  * If you do not wish that, delete this exception notice.  
  40.  */
  41.  
  42. #include <stdio.h>
  43. #include "_scm.h"
  44.  
  45. PROC1 (s_eq_p, "eq?", tc7_rpsubr, scm_eq_p);
  46. #ifdef __STDC__
  47. SCM
  48. scm_eq_p (SCM x, SCM y)
  49. #else
  50. SCM
  51. scm_eq_p (x, y)
  52.      SCM x;
  53.      SCM y;
  54. #endif
  55. {
  56.   return ((x==y)
  57.       ? BOOL_T
  58.       : BOOL_F);
  59. }
  60.  
  61.  
  62. PROC1 (s_eqv_p, "eqv?", tc7_rpsubr, scm_eqv_p);
  63. #ifdef __STDC__
  64. SCM
  65. scm_eqv_p (SCM x, SCM y)
  66. #else
  67. SCM
  68. scm_eqv_p (x, y)
  69.      SCM x;
  70.      SCM y;
  71. #endif
  72. {
  73.   if (x==y) return BOOL_T;
  74.   if IMP(x) return BOOL_F;
  75.   if IMP(y) return BOOL_F;
  76.   /* this ensures that types and scm_length are the same. */
  77.   if (CAR(x) != CAR(y)) return BOOL_F;
  78.   if NUMP(x) {
  79. # ifdef BIGDIG
  80.     if BIGP(x) return (0==scm_bigcomp(x, y)) ? BOOL_T : BOOL_F;
  81. # endif
  82. #ifdef FLOATS
  83.     if (REALPART(x) != REALPART(y)) return BOOL_F;
  84.     if (CPLXP(x) && (IMAG(x) != IMAG(y))) return BOOL_F;
  85. #endif
  86.     return BOOL_T;
  87.   }
  88.   return BOOL_F;
  89. }
  90.  
  91. extern SCM scm_array_equal ();
  92.  
  93. PROC1 (s_equal_p, "equal?", tc7_rpsubr, scm_equal_p);
  94. #ifdef __STDC__
  95. SCM
  96. scm_equal_p (SCM x, SCM y)
  97. #else
  98. SCM
  99. scm_equal_p (x, y)
  100.      SCM x;
  101.      SCM y;
  102. #endif
  103. {
  104.   CHECK_STACK;
  105.  tailrecurse: POLL;
  106.     if (x==y) return BOOL_T;
  107.     if (IMP(x)) return BOOL_F;
  108.     if (IMP(y)) return BOOL_F;
  109.     if (CONSP(x) && CONSP(y)) {
  110.         if FALSEP(scm_equal_p(CAR(x), CAR(y))) return BOOL_F;
  111.         x = CDR(x);
  112.         y = CDR(y);
  113.         goto tailrecurse;
  114.     }
  115.     /* this ensures that types and scm_length are the same. */
  116.     if (CAR(x) != CAR(y)) return BOOL_F;
  117.     switch (TYP7(x)) {
  118.         default: return BOOL_F;
  119.     case tc7_string: return scm_string_equal_p(x, y);
  120.     case tc7_vector: return scm_vector_equal_p(x, y);
  121.     case tc7_lvector:
  122.       {
  123.         SCM hook;
  124.         hook = scm_get_lvector_hook (x, LV_EQUAL_FN);
  125.         if (hook == BOOL_F)
  126.           return scm_vector_equal_p (x, y);
  127.         else
  128.           return scm_apply (hook,
  129.                 scm_cons (x, scm_cons (y, EOL)),
  130.                 EOL);
  131.       }
  132.     case tc7_smob: {
  133.             int i = SMOBNUM(x);
  134.             if (!(i < scm_numsmob)) return BOOL_F;
  135.             if (scm_smobs[i].equalp)
  136.           return (scm_smobs[i].equalp)(x, y);
  137.         else
  138.           return BOOL_F;
  139.           }
  140.     case tc7_bvect: case tc7_uvect: case tc7_ivect:
  141.     case tc7_fvect:    case tc7_cvect: case tc7_dvect:
  142.       if (   scm_tc16_array
  143.           && scm_smobs[0x0ff & (scm_tc16_array >> 8)].equalp)
  144.         return scm_array_equal(x, y);
  145.     }
  146.     return BOOL_F;
  147. }
  148.  
  149.  
  150. #ifdef __STDC__
  151. void
  152. scm_init_eq (void)
  153. #else
  154. void
  155. scm_init_eq ()
  156. #endif
  157. {
  158. #include "eq.x"
  159. }
  160.  
  161.